<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>03_JS的数据类型</title>
</head>
<body>
<script>
    //JS数据类型=原始类型+引用类型
    //原始类型
    var a = 1;
    var b = 9.9;//整数小数都是Num
    console.log(a, typeof a, b, typeof b);
    var c = 'hello';
    var d = "world";//单引双引都是String
    console.log(c, typeof c, d, typeof d);
    var e = true;
    var f = false;//true和false是Boolean
    console.log(e, typeof e, f, typeof f);
    var g;
    console.log(g, typeof g);//声明了变量但未赋值会得到undefiend 未定义型
    //引用类型Array Object Function。。。
    let obj = {};
    console.log(obj, typeof obj);//{}'object'
    obj.name = '张三';
    obj.age = 18;
    console.log(obj, typeof obj);//{name:'张三'，age:'18'}'object'
    console.log(obj.name, obj.age)

    //自定义对象的第2中写法
    let obj2 = {
        name: '李四',
        age: 20
    };
    obj2.gender = '男';
    console.log(obj2, typeof obj2);//{name:'李四'，age:'20'}'object'
    console.log(obj2.name, obj2.age, obj2.gender)

    //数组
    let arr = ['张三', 1, 6.6, true];
    console.log(arr);
    console.log(arr[0], arr[1], arr[2], arr[3])
    console.log(arr[100]);//undefined 访问数组中不存在的元素也会得到undefined

    //Number() 将参数转为数字
    console.log(Number(true), typeof Number(true));//1'number'
    console.log(Number(false), typeof Number(false));
    console.log(Number('3'));
    console.log(Number(3))
    console.log(Number(6.6))
    console.log(Number('哈哈哈'))

    //Boolean() 将参数转为Boolean
    //0，NaN,NULL,undefined,false,'' 这五个特殊值转为布尔是false
    console.log(Boolean(1), typeof Boolean(1));//true'boolean'
    console.log(Boolean(0));
    console.log(Boolean(''));
    console.log(Boolean(' '));//true
    console.log(Boolean(null));
    console.log(Boolean(undefined));
    console.log(Boolean(NaN));
    console.log(Boolean('早上好'));//true



</script>
</body>
</html>